<?php
    class Profil {
        //Alias sur table : pro
        public $id_profil;
        public $libelle;
        public $valide;

        //Constructeur complet
        public function __construct($id_profil, $libelle, $valide) {
                $this->setId($id_profil);
                $this->setLibelle($libelle);
                $this->setValide($valide);
        }
		
        //Affiche le libellé du Profil
        //Paramètre : aucun
        //Retourne (String)
        public function __toString() {
            return $this->libelle;
        }
        
        //Récupère tout les profils
        //Paramètre : OPTIONNEL (Booléen)valide
        //Retourne collection de Profil
        public static function getProfils($valide = true) {
            $sql =  'SELECT
                        pro.id_profil as proid_profil, pro.libelle as prolibelle, pro.valide as provalide
                    FROM profil pro
                    WHERE
                        pro.valide = '.intval($valide);
            $ps = Db::Execute($sql, true);
            $tabRetour = array();
            foreach($ps as $p) {
                $tabRetour[] = new Profil($p['proid_profil'], $p['prolibelle'], $p['provalide']);
            }

            return $tabRetour;
        }
		
        //Crée un objet Profil grâce à son ID
        //Paramètre : (int)id
        //Retourne (Profil)
        public static function rechercheProfil($id) {
            $sql =  'SELECT
                        pro.id_profil as proid_profil, pro.libelle as prolibelle, pro.valide as provalide
                    FROM profil pro
                    WHERE
                        pro.id_profil = '.intval($id);
            $ps = Db::Execute($sql, true);
            foreach($ps as $p) {
                return new Profil($p['proid_profil'], $p['prolibelle'], $p['provalide']);
            }

            return null;
        }
		
        //GETTERS ET SETTERS
        public function getId() {return $this->id_profil;}
        public function getLibelle() {return $this->libelle;}
        public function getValide() {return $this->valide;}

        public function setId($temp) {$this->id_profil = intval($temp);}
        public function setLibelle($temp) {$this->libelle = $temp;}
        public function setValide($temp) {$this->valide = intval($temp);}
		
    }

?>